<%@page import="java.text.DecimalFormat"%>
<%@page import="objects.AnalyticDataSource"%>
<%@page import="models.DomainAnalyticModel"%>
<%@page import="models.config.SiteConfigModel"%>
<%@page import="models.OutLinkModel"%>
<%@page import="java.util.List"%>
<%@page import="models.GoogleAnalyticModel"%>
<%@page import="models.GoogleAdsenseModel"%>
<%@page import="models.DomainModel"%>
<%@page import="models.OwnerDomainModel"%>
<%@page import="models.UserModel"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
	TreeMap check = (TreeMap) request.getAttribute("check");
	String success = (String) request.getAttribute("success");
	SiteConfigModel siteConfig = (SiteConfigModel) request.getAttribute("config");
	String image = UrlHelper.getServerUrl(request) + "/blobstore-serve?blob-key=" + siteConfig.getLogo();
	DomainModel domain = (DomainModel) request.getAttribute("domain");
	GoogleAdsenseModel googleAdsense = (GoogleAdsenseModel) request.getAttribute("googleAdsense");
	GoogleAnalyticModel googleAnalytic = (GoogleAnalyticModel) request.getAttribute("googleAnalytic");
	OutLinkModel outlink = (OutLinkModel) request.getAttribute("outlink");
	DomainAnalyticModel analytic = (DomainAnalyticModel) request.getAttribute("domainAnalytic");
%>


<jsp:include page="/layouts/demo/header.jsp">
    <jsp:param name="title" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="description" value="<%=siteConfig.getMetaDescription()%>" />
    <jsp:param name="keywords" value="<%=siteConfig.getMetaKeywords()%>" />
    <jsp:param name="ogsite_name" value="<%=siteConfig.getSiteName()%>" />
    <jsp:param name="ogtitle" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="ogurl" value="<%=UrlHelper.getServerUrl(request)%>" />
    <jsp:param name="ogimage" value="<%=image %>" />
    <jsp:param name="ogdescription" value="<%=siteConfig.getMetaDescription()%>" />
</jsp:include>

		<div class="dir">
			<a href="/home">Home</a> > <%=domain.getDomain() %>
		</div>
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form"><%=domain.getDomain() %> - Domain Information</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="domain">
							Domain Name
						</td>
						<td>
							<%=domain.getDomain() %>
						</td>
					</tr>
					<tr>
						<td>
							Title
						</td>
						<td>
							<%=domain.getTitle() %>
						</td>
					</tr>
					<tr>
						<td>
							Keyword
						</td>
						<td>
							<%=domain.getKeywords() %>
						</td>
					</tr>
					<tr>
						<td>
							Description
						</td>
						<td>
							<%=domain.getDescription() %>
						</td>
					</tr>
					<tr>
						<td>
							Created
						</td>
						<td>
							<%=domain.getCreated() %>
						</td>
					</tr>
					<tr>
						<td>
							Updated
						</td>
						<td>
							<%=domain.getUpdated() %>
						</td>
					</tr>
					<tr>
						<td>
							ScreenShot
						</td>
						<td>
							<img alt="" src="http://immediatenet.com/t/t_a?Size=1024x768&URL=<%=domain.getDomain()%>">
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form"><%=domain.getDomain() %> - Ranking</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="domain">
							Google Page Rank
						</td>
						<td>
							<%=domain.getGooglePageRank() %>
						</td>
					</tr>
					<tr>
						<td>
							Alexa Rank
						</td>
						<td>
							<%=domain.getAlexaRank() %>
						</td>
					</tr>
					<tr>
						<td>
							Daily Visitor
						</td>
						<td>
							<%=domain.getDailyVisitor() %>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form"><%=domain.getDomain() %> -  Technical Info</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="domain">
							Web server
						</td>
						<td>
							<%=domain.getWebServer() %>
						</td>
					</tr>
					<tr>
						<td>
							Programming Language 
						</td>
						<td>
							<%=domain.getProgrammingLanguage() %>
						</td>
					</tr>
					<tr>
						<td>
							Javascript library
						</td>
						<td>
							<%=domain.getJavascriptLibrary() %>
						</td>
					</tr>
					<tr>
						<td>
							Age
						</td>
						<td>
							<%=domain.getAge() %>
						</td>
					</tr>
					<tr>
						<td>
							Ip Address
						</td>
						<td>
							<%=domain.getIpAddress() %>
						</td>
					</tr>
					<tr>
						<td>
							Who is
						</td>
						<td>
							<div style="height: 110px; margin-bottom: 10px; overflow: hidden; width: 500px;">
							<%=domain.getWhois() %>
							</div>
							<a href="/whois?domain=<%=domain.getDomain()%>">More info whois</a>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form"><%=domain.getDomain() %> -  Contact Info</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="domain">
							Site's same Google Analytic (<%=domain.getGoogleAnalyticId() %>):
						</td>
						<td>
						<%
							if (googleAnalytic != null) {
								List<String> analyticDomains = (List<String>) googleAnalytic.getDomains();
								for (int i = 0; i < analyticDomains.size(); i++) {
						%>
							<a href="#"><%=analyticDomains.get(i) %></a>
						<%  	}
							} %>
						</td>
					</tr>
					<tr>
						<td>
							Site's same Google Adsense (<%=domain.getGoogleAdsenseId() %>):
						</td>
						<td>
							<%
							if (googleAdsense != null) {
								List<String> adsenseDomains = (List<String>) googleAdsense.getDomains();
								for (int i = 0; i < adsenseDomains.size(); i++) {
						%>
							<a href="#"><%=adsenseDomains.get(i) %></a>
						<%  	}
							} %>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form"><%=domain.getDomain() %> -  Link</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="domain">
							Inlink:
						</td>
						<td>
						<%
							String[] inlinks = domain.getInlink().split(",");
							for (int i = 0; i < inlinks.length; i++) {
						%>
							<a href="#"><%=inlinks[i] %></a>
						<%  }  %>
						</td>
					</tr>
					<tr>
						<td>
							Out link
						</td>
						<td>
							<%
							if (outlink != null) {
								List<String> outlinks = (List<String>) outlink.getDomains();
								for (int i = 0; i < outlinks.size(); i++) {
							%>
							<a href="#"><%=outlinks.get(i) %></a>
							<%  }
							}
							%>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form"><%=domain.getDomain() %> -  Domain Traffic Graph</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="50%">
							<img src="http://traffic.alexa.com/graph?c=1&amp;u=<%=domain.getDomain() %>&amp;r=6m&amp;y=t&amp;z=3&amp;h=200&amp;w=280&amp;b=FFFFFF">
						</td>
						<td>
							<img src="http://traffic.alexa.com/graph?c=1&amp;u=<%=domain.getDomain() %>&amp;r=6m&amp;y=r&amp;z=3&amp;h=200&amp;w=280&amp;b=FFFFFF">
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td><div class="title-form">Visitors by Country for: <%=domain.getDomain() %></div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>
							<%
								String countryVisitor = domain.getCountryVisitor();
								String[] countries = countryVisitor.split(",");
								
							%>
							<script type='text/javascript' src='https://www.google.com/jsapi'></script>
						    <script type='text/javascript'>
						     google.load('visualization', '1', {'packages': ['geochart']});
						     google.setOnLoadCallback(drawRegionsMap);
						
						      function drawRegionsMap() {
						        var data = google.visualization.arrayToDataTable([
						          ['Country', 'Percent (%)'],
						          <%
						          	if (!countryVisitor.isEmpty()) {
								    	for (int i = 0; i < countries.length; i++) {
								    		String[] visitor = countries[i].split("-");
							      %>
							      ['<%=visitor[0] %>', <%=visitor[1] %>],
							      <%	}
						          	}
								    %>
						        ]);
						
						        var options = {numberFormat:'.#'};
						
						        var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
						        chart.draw(data, options);
						    };
						    </script>
						    <div id="chart_div" style="height: 500px;"></div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">HTML validation for: <%=domain.getDomain() %></div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%">Error</td>
						<td><%=domain.getValidError() %></td>
					</tr>
					<tr>
						<td width="30%">Warning</td>
						<td><%=domain.getValidWarnings() %></td>
					</tr>
				</tbody>
			</table>
		</div>
		<br />
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">RSS Page: <%=domain.getDomain() %></div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%">Error</td>
						<td><%=domain.getValidError() %></td>
					</tr>
					<tr>
						<td width="30%">Warning</td>
						<td><%=domain.getValidWarnings() %></td>
					</tr>
				</tbody>
			</table>
		</div>
		
		<br />
		<%
if (analytic != null) {
	AnalyticDataSource visitPerMonth = analytic.getVisitPerMonth();
	AnalyticDataSource visitPerYear = analytic.getVisitPerYear();
	AnalyticDataSource visitPerMonthByLocation = analytic.getVisitPerMonthByLocation();
%>
		<div class="submit-form">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td><div class="title-form">Analytic Info</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>
						    <script type="text/javascript">
						      google.load("visualization", "1", {packages:["corechart"]});
						      google.setOnLoadCallback(drawChartVisitPerMonth);
						      google.setOnLoadCallback(drawChartVisitPerYear);
						      function drawChartVisitPerMonth() {
						        var data = google.visualization.arrayToDataTable([
						          ['Date', 'Visitor', 'Page View'],
						          <%
						          for(int i = 0; i < visitPerMonth.getEntries().size(); i++) {
						          %>
						          ['<%=visitPerMonth.getEntries().get(i).getGa_date()%>',  <%=visitPerMonth.getEntries().get(i).getGa_visits()%>,      <%=visitPerMonth.getEntries().get(i).getGa_pageviews()%>]
						          <%  if (i < visitPerMonth.getEntries().size() - 1) { %>,  
						          <%  } 
						          } %>
						        ]);
						
						        var options = {
						          title: 'Visit Per Month'
						        };
						
						        var chartVisitPerMonth = new google.visualization.LineChart(document.getElementById('visit_per_month'));
						        chartVisitPerMonth.draw(data, options);
						      }
						      
						      function drawChartVisitPerYear() {
						          var data = google.visualization.arrayToDataTable([
						            ['Month', 'Visitor', 'Page View'],
						            <%
						            for(int i = 0; i < visitPerYear.getEntries().size(); i++) {
						            %>
						            ['<%=visitPerYear.getEntries().get(i).getGa_month()%>',  <%=visitPerYear.getEntries().get(i).getGa_visits()%>,      <%=visitPerYear.getEntries().get(i).getGa_pageviews()%>]
						            <%  if (i < visitPerYear.getEntries().size() - 1) { %>,  
						            <%  } 
						            } %>
						          ]);
						
						          var options = {
						            title: 'Visit Per Year'
						          };
						
						          var chartVisitPerYear = new google.visualization.LineChart(document.getElementById('visit_per_year'));
						          chartVisitPerYear.draw(data, options);
						        }
						    </script>
						    
						    <script type='text/javascript'>
						     google.setOnLoadCallback(drawRegionsMap);
						
						      function drawRegionsMap() {
						        var data = google.visualization.arrayToDataTable([
						          ['Country', 'Visits'],
						          <%
						          for(int i = 0; i < visitPerMonthByLocation.getEntries().size(); i++) {
						          %>
						          ['<%=visitPerMonthByLocation.getEntries().get(i).getGa_country()%>', <%=visitPerMonthByLocation.getEntries().get(i).getGa_visits()%>]
						          <%  if (i < visitPerMonthByLocation.getEntries().size() - 1) { %>,  
						          <%  } 
						          } %>
						        ]);
						
						        var options = {
						        	title: 'Visit Per Month By Location'
						        };
						
						        var chart = new google.visualization.GeoChart(document.getElementById('visit_per_month_by_location'));
						        chart.draw(data, options);
						    };
						    </script>

							<div id="visit_per_month" style="width: 600px; height: 300px;"></div>
							<div id="visit_per_year" style="width: 600px; height: 300px;"></div>
							<div id="visit_per_month_by_location" style="width: 600px; height: 500px;"></div>
							<br />
							<table width="100%">
								<thead>
									<tr>
										<th>Countries</th>
										<th>Visits</th>
										<th>% New Visit</th>
										<th>Time on page</th>
										<th>Bounces</th>
									</tr>
								</thead>
								<tbody>
								<%
								  DecimalFormat dec = new DecimalFormat("###.##");
						          for(int i = 0; i < visitPerMonthByLocation.getEntries().size(); i++) {
						        %>
						        	<tr>
						        		<td><%=visitPerMonthByLocation.getEntries().get(i).getGa_country()%></td>
						        		<td><%=visitPerMonthByLocation.getEntries().get(i).getGa_visits()%></td>
						        		<td><%=dec.format(Double.parseDouble(visitPerMonthByLocation.getEntries().get(i).getGa_percentNewVisits()))%>%</td>
						        		<td><%=dec.format(Double.parseDouble(visitPerMonthByLocation.getEntries().get(i).getGa_avgTimeOnPage()))%></td>
						        		<td><%=visitPerMonthByLocation.getEntries().get(i).getGa_bounces()%></td>
						        	</tr>
						        <% } %>
								</tbody>
							</table>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
<% } %>
<jsp:include page="/layouts/demo/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>